package cn.edu.zafu.bigdata.lb;

public class Cube {
    // 定义属性
    private double length;
    private double width;
    private double height;

    // 构造方法
    public Cube(double length, double width, double height) {
        this.length = length;
        this.width = width;
        this.height = height;
    }

    // 获取方法
    public double getLength() {
        return length;
    }

    public double getWidth() {
        return width;
    }

    public double getHeight() {
        return height;
    }

    // 重写equals方法
    @Override
    public boolean equals(Object obj) {
        // 检查是否为同一对象
        if (this == obj) {
            return true;
        }
        // 检查obj是否为null
        if (obj == null) {
            return false;
        }
        // 检查是否为Cube类型
        if (!(obj instanceof Cube)) {
            return false;
        }
        // 类型转换
        Cube other = (Cube) obj;
        // 比较属性值
        return Double.compare(this.length, other.length) == 0 &&
                Double.compare(this.width, other.width) == 0 &&
                Double.compare(this.height, other.height) == 0;
    }

    // 测试用例
    public static void main(String[] args) {
        Cube cube1 = new Cube(3.0, 4.0, 5.0);
        Cube cube2 = new Cube(3.0, 6.0, 9.0);
        Cube cube3 = new Cube(3.0, 4.0, 5.0);

        // 测试相等性
        System.out.println("cube1 equals cube2: " + cube1.equals(cube2));
        System.out.println("cube1 equals cube3: " + cube1.equals(cube3));
    }
}

